#include <iostream>


class Animal
{
public:
    virtual void speak()
    {
        std::cout<<"动物说话"<<std::endl;
    }
};

class Dog:public Animal
{
public:
    void speak()
    {
        std::cout<<"狗叫"<<std::endl;
    }
};

class Cat:public Animal
{
public:
    void speak()
    {
        std::cout<<"猫叫"<<std::endl;
    }
};

//向上转型:基类的引用或者指针可以访问子类的对象
// void Speak(Animal& a)
// {
//     a.speak();
// }
void Speak(Animal* a)
{
    a->speak();
}

int main()
{
    Dog d;
    Speak(&d);

    Cat c;
    Speak(&c);
    return 0;
}